import basegraphunit from './basegraphunit.js'
import coorPkg from '../..//struct/coord.js'

class Polygon extends basegraphunit.BaseGraphUnit {
    constructor() {
        super();
        this.pos = new coorPkg.MultiPos();
        this.strPosition = "";
    }

    translateSubInfo(tx,ty){
        this.strPosition = this.pos.toString();
    }

    toJson() { 
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["strPosition"] = this.pos.toString();
        return jsonobj;
    }
    fromJson(obj) { 
        super.fromJson(obj);
        var sx = obj["sx"];
        var sy = obj["sy"];
        if (sx != null && sy != null) {
            this.pos.setPosByString(sx, sy);
        }
        else {
            this.strPosition = obj["strPosition"];
            this.pos.fromString(this.strPosition);
        }
    }
    cloneCopy() {
        var pNewInfo = new Polygon();
        super.cloneCopy(pNewInfo);
        pNewInfo.strPosition = this.strPosition;
        return pNewInfo;
    }
}

export default { Polygon }